#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <QObject>
#include <QDateTime>
#include <QXmlStreamWriter>

#include "global.h"


// 定义参数结构体
typedef struct ParamItem{
    QString strName;
    QString strNote;
    ePBType type;
}struParamItem;

// 协议项
typedef struct ProtocolItem{
    QString strName;
    QString strNote;
    quint8 iCode;
    quint8 iArrayCount;
    bool bArray;
    bool bPrivate;
    eParamOptionAccess access;
    QList<struParamItem> paramList;
}struProtocolItem;

class Protocol : public QObject
{
    Q_OBJECT
public:
    explicit Protocol(QObject *parent = nullptr);

    bool load(const QString strFileName=QString());
    bool save(const QString strFileName=QString());


    QString strFileName() const;
    void setStrFileName(const QString &strFileName);

    QString strVersion() const;
    void setStrVersion(const QString &strVersion);

    QList<struProtocolItem> ProtocolList() const;
    void setProtocolList(const QList<struProtocolItem> &ProtocolList);

    struProtocolItem itemAt(int n);
    void removeItem(int n);
    int itemCount();
    void addItem(const struProtocolItem item);
    void setItem(int n, const struProtocolItem item);

    QString strAuthor() const;
    void setStrAuthor(const QString &strAuthor);

    QDateTime lastEditTime() const;

    QString strName() const;
    void setStrName(const QString &strName);



signals:

private:
    QString m_strFileName;

    QString m_strAuthor;
    QString m_strName;
    QString m_strVersion;
    QDateTime m_lastEditTime;

    QList<struProtocolItem> m_ProtocolList;

    void saveProtocolItem(QXmlStreamWriter& stream, struProtocolItem protocolItem);
    void saveParamItem(QXmlStreamWriter& stream, struParamItem param);
};

#endif // PROTOCOL_H
